package com.sirun.ble.bean;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.ScanResult;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * @author : hzw
 */
public class BleDeviceBean implements Parcelable {

    public BluetoothDevice dev;
    public ScanResult scanResult;

    public BleDeviceBean(BluetoothDevice device, ScanResult result) {
        dev = device;
        scanResult = result;
    }


    protected BleDeviceBean(Parcel in) {
        dev = in.readParcelable(BluetoothDevice.class.getClassLoader());
        scanResult = in.readParcelable(ScanResult.class.getClassLoader());
    }

    public static final Creator<BleDeviceBean> CREATOR = new Creator<BleDeviceBean>() {
        @Override
        public BleDeviceBean createFromParcel(Parcel in) {
            return new BleDeviceBean(in);
        }

        @Override
        public BleDeviceBean[] newArray(int size) {
            return new BleDeviceBean[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        BleDeviceBean bleDev = (BleDeviceBean) o;
        return Objects.equals(dev, bleDev.dev);
    }

    @Override
    public int hashCode() {
        return Objects.hash(dev);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(dev, flags);
        dest.writeParcelable(scanResult, flags);
    }
}
